// axios二次封装
import axios from "axios";
import nprogress from "nprogress";
import "nprogress/nprogress.css";

//创建axios实例
const ajax = axios.create({
  baseURL: "/topic", //请求基本路径
  timeout: 5000, //超时时间
});
//请求拦截器
ajax.interceptors.request.use((config) => {
  nprogress.start();
  return config;
});
//响应拦截器
ajax.interceptors.response.use(
  (response) => {
    nprogress.done();
    return response.data;
  },
  (error) => {
    nprogress.done();
    alert(error);
    return new Promise(() => {});
  }
);
export default ajax;
